package org.xtense.rcp.editors.action;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class NewDialog extends Dialog {
	public static String Element = "Element";
	public static String Attribute = "Attribute";
	private String type;
	private Text name;
	private Text value;
	private String nameV;
	private String valueV;

	/**
	 * @param parentShell
	 */
	protected NewDialog(Shell parentShell) {
		super(parentShell);
	}
	
	public NewDialog(Shell shell, String type) {
		this(shell);
		this.type = type;
	}
	
	protected Control createDialogArea(Composite parent) {
		Composite comp = (Composite) super.createDialogArea(parent);
		Group group = new Group(comp, SWT.NONE);
		group.setText("New " + type);
		GridLayout layout = new GridLayout();
		layout.marginHeight = 20;
		layout.marginWidth = 20;
		layout.numColumns = 2;
		group.setLayout(layout);
		new Label(group, SWT.NONE).setText("Name: ");
		name = new Text(group, SWT.BORDER | SWT.SINGLE);
		if (Element.equals(type)) {
			new Label(group, SWT.NONE).setText("Text: ");
		} else {
			new Label(group, SWT.NONE).setText("Value: ");
		}
		value = new Text(group, SWT.BORDER | SWT.SINGLE);

		return parent;
	}
	
	public String getName() {
		return nameV;
	}

	public String getValue() {
		return valueV;
	}
	
	protected void okPressed() {
		nameV = name.getText();
		valueV = value.getText();
		super.okPressed();
	}

}
